<?php
namespace app\circle\model;

class MeetingSignModel extends BaseModel
{
    protected $name = 'circle_meeting_sign'; //定义用户表
    //开启自动写入时间戳
    protected $autoWriteTimestamp = true;
    // 定义自动完成的属性
    protected $auto = []; //新增修改
    protected $insert = []; //插入
    protected $update = []; //修改

    protected function getStatusTextAttr($value,$data){
        $arr=[1=>'未处理',2=>'已报名',3=>'已放弃'];
        return $arr[$data['status']];
    }

    /**
     * 会议报名
     */
    public function sign($meetingId,$mobile,$name){
        $meetingModel = new MeetingModel();
        $meetingInfo = $meetingModel->where('meeting_id',$meetingId)->find();
        if(empty($meetingInfo)){
            $this->error = '会议不存在！';
            return false;
        }
        $time = time();
        if($time>$meetingInfo['sign_start_time'] && $time<$meetingInfo['sign_end_time']){
            $this->error = '该会议未开放报名！';
            return false;
        }
        if($this->where('meeting_id',$meetingId)->where('mobile',$mobile)->find()){
            $this->error = '您已报名，工作人员随后与您联系！';
            return false;
        }
        $data['dept_id'] = $meetingInfo['dept_id'];
        $data['dept_path'] = $meetingInfo['dept_id'];
        $data['dept_name'] = $meetingInfo['dept_name'];
        $data['meeting_id'] = $meetingId;
        $data['meeting_name'] = $meetingInfo['meeting_name'];
        $data['mobile'] = $mobile;
        $data['name'] = $name;
        $this->addData($data);
        return true;
    }

}